package com.augurit.gzcgwsp.smartformCsdlwj.convert;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.dozer.DozerBeanMapper;

import com.augurit.gzcgwsp.lhsp.web.form.LhspSendItemNoticeForm;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwSrDlzyForFx;
import com.augurit.gzcgwsp.smartformCsdlwj.entity.YwSrDlzy;
import com.augurit.gzcgwsp.smartformCsdlwj.web.form.DlzyForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxTwoForm;

/**
 * 道路占用
 * @author Administrator
 *
 */
 
public class YwSrDlzyConvertor {
    public static DlzyForm convertVoToForm(YwSrDlzy entity) {
        if (entity == null) return null;
        DlzyForm form = new DozerBeanMapper().map(entity, DlzyForm.class);        
        return form;
    }
    
	
	public static void convertSendItemNoticeFormToForm(LhspSendItemNoticeForm sendItemNoticeForm,DlzyForm form) {
        Long id = form.getId();
		new DozerBeanMapper().map(sendItemNoticeForm, form);
		form.setId(id);
    }


    
    public static void convertFormToQyxxForm(DlzyForm form, YwComQyxxForm qyxxForm) {
        if (form == null) return;
        if (qyxxForm == null) qyxxForm = new YwComQyxxForm();

        new DozerBeanMapper().map(form, qyxxForm);
        if(StringUtils.isNotBlank(form.getQybh())){
        	qyxxForm.setId(Long.parseLong(form.getQybh()));
        }        
    }
    
    //转换到临时占用单位form
    public static void convertFormToQyxxTwoForm(DlzyForm form, YwComQyxxTwoForm qyxxTwoForm) {
        if (form == null) return;
        if (qyxxTwoForm == null) qyxxTwoForm = new YwComQyxxTwoForm();
        if(StringUtils.isNotBlank(form.getQybhTwo())){
        	qyxxTwoForm.setId(Long.parseLong(form.getQybhTwo()));
        }
        if(StringUtils.isNotBlank(form.getAqfzr())){
        	qyxxTwoForm.setAqfzrTwo(form.getAqfzr());
        }
        if(StringUtils.isNotBlank(form.getZydwAddress())){
        	qyxxTwoForm.setAddressTwo(form.getZydwAddress());
        }
        if(StringUtils.isNotBlank(form.getZydwTel())){
        	qyxxTwoForm.setTelTwo(form.getZydwTel());
        }
        if(StringUtils.isNotBlank(form.getZydwLxr())){
        	qyxxTwoForm.setLxrTwo(form.getZydwLxr());
        }
    }

    public static void convertQyxxFormToForm(YwComQyxxForm qyxxForm, DlzyForm form) {
        if (qyxxForm == null) return;
        if (form == null) form = new DlzyForm();
        
        new DozerBeanMapper().map(qyxxForm, form);
        form.setQybh(qyxxForm.getId().toString());
    }
    
    public static void convertFormToVo(DlzyForm form, YwSrDlzy entity) {
        if (form == null) return;
        if (entity == null) entity = new YwSrDlzy();
        
        new DozerBeanMapper().map(form, entity);
    }
    
    public static List<DlzyForm> convertVoListToFormList(List<YwSrDlzy> ywSrDlzyList) {
        if(ywSrDlzyList != null && ywSrDlzyList.size() > 0) {
            List<DlzyForm> dlzyFormList = new ArrayList();
            for(int i=0; i<ywSrDlzyList.size(); i++) {
            	dlzyFormList.add(convertVoToForm(ywSrDlzyList.get(i)));
            }
            return dlzyFormList;
        }
        return null;
    }
    
    public static List<YwSrDlzy> convertFormListToVoList(List<DlzyForm> dlzyFormList) {
        if(dlzyFormList != null && dlzyFormList.size() > 0) {
            List<YwSrDlzy> ywSrDlzyList = new ArrayList();
            for(int i=0; i<dlzyFormList.size(); i++) {
                YwSrDlzy ywSrDlzy = new YwSrDlzy();
                convertFormToVo(dlzyFormList.get(i), ywSrDlzy);
                ywSrDlzyList.add(ywSrDlzy);
            }
            return ywSrDlzyList;
        }
        return null;
    }
    
    public static void convertFormToYwSrDlzyForFx(DlzyForm form, YwSrDlzyForFx entity) {
        if (form == null) return;
        if (entity == null) entity = new YwSrDlzyForFx();        
        new DozerBeanMapper().map(form, entity);
    }
}